Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CI] Enhance the pipeline with git diff method #4737

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

ueqri
Copy link
Contributor

@ueqri ueqri commented Apr 29, 2021

Summary

This PR mainly introduces git diff and adds a new main pipeline for current CI, as an extension of the discussions in #4715.
Blow are my ideas of new structure of CI:
ci-main

To control the CI workflow better and make the structure more perspicuous, I add a main pipeline to:

  1. do formatting, which will be done before both build & docs pipeline
  2. diff code changes between HEAD & master (to determine which pipeline, build or docs, should run next)

Pros

  • remedy the unexpected behavior (docs pipeline is triggered twice when both codes and docs changes commit together)
  • make the CI more explicit
  • separate format stage, so that we can add stages and jobs as downstream of formatting in main pipeline
  • easier to add diff rules (e.g. use wildcard or regex) in git diff script than using Azure path filter before

Cons

  • need to introduce another pipeline, which may be not a good choice for Azure Ops. (TBH, pipeline trigger is much smoother to maintain than the flow-control methods for stages or jobs)

Test

I test four cases by push to branch directly or start a PR from another user's branch to my test branch test-CI-features (with minimal CI). The features work successfully! Here are the results:

Details about experiment result

Cases

  • only codes changed => run build then docs pipeline
  • only docs changed => only run docs pipeline
  • both codes and docs changed => run build then docs pipeline
  • only README.md changed => won't trigger any CI

Test push trigger

Screenshot_2021-04-21_13-24-32

Test PR trigger

Screenshot_2021-04-29_02-05-25

PS

For exclude rules, it's a bit hard to separate the path-filter(a part of Azure YAML schema) and the diff-exclude-rules to one place. So as a second-best solution to reduce the complexity, I pick up the diff-exclude-rules to the head of the script lines, and add comments to attract attention in YAML file.

...
- script: | 
     # Add all docs path to this array
     DOCS_LISTS=("doc" "*.md")
     ...
# Exclude Rules:
# 1. path-filter in trigger and pr, 
#    this is NOT exclude rules for documentation,
#    set this rule only to avoid any CI run.
# 2. DOCS_LISTS in diff script, 
#    the lists contains all documentation-related files,
#    fill the list to help git-diff recognize docs changes.

Copy link
Member

@kunaltyagi kunaltyagi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional changes:

  • README: modify the documentation badge

Question:

  • If the pipeline is run on master branch (post PR merge), what will the diff stage do? Will it skip the pipeline?

@ueqri
Copy link
Contributor Author

ueqri commented Apr 30, 2021

Thank you for reviewing!

README: modify the documentation badge

I think the documentation badge in README seems fine, should we add badge for main pipeline. Or did I misunderstand your change request?

If the pipeline is run on master branch (post PR merge), what will the diff stage do? Will it skip the pipeline?

It's certainly a problem for running on master.I tested direct push using git diff HEAD HEAD~1 and it was modified for PR check without much concern:sweat_smile:, sorry for that. So I think adding a check for master branch or PR merge in script and use git diff HEAD HEAD~1 for direct push will address this issue.

Copy link
Member

@kunaltyagi kunaltyagi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So far looks good to me. What's the plan here @ueqri ?

@ueqri
Copy link
Contributor Author

ueqri commented Jun 5, 2021

So far looks good to me. What's the plan here @ueqri ?

Sorry for replying so late.

I think this enhancement is ready for further developments, e.g. enabling CUDA build on CI(GSoC 2021 Project), integrating clang-tidy and sanitizers for CI(#4629), separating build and test as different stages(#3947), etc.

And I plan to add a documentation as descriptions about CI structure in .ci folder. Then could we merge this PR and test the new pipelines in this drafted PR #4715?

@kunaltyagi
Copy link
Member

Sounds good to me. Could you clean up the code, add comments, etc. if needed and ping again (or asap if not needed) for the review?

@ueqri
Copy link
Contributor Author

ueqri commented Jun 8, 2021

Sounds good to me. Could you clean up the code, add comments, etc. if needed and ping again (or asap if not needed) for the review?

Thanks for your kind help! I would do it soon. 😀

@ueqri
Copy link
Contributor Author

ueqri commented Jun 12, 2021

I think it's ready for 🚀 . And we could update the structure.md for detailed explanations whenever there are some features introduced to CI in the future. 😆

Copy link
Member

@kunaltyagi kunaltyagi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding overall structure, I see 2 git diff stages. I have some questions on which I need some clarification:

  • Could we have a single git diff stage and set the variables there?
  • What's the benefit of using pipeline trigger compared to just having them as different stages, included from a separate file? (Since GCC -> generate doc + tutorials is 100% assured)

@@ -12,7 +12,10 @@ trigger:
- README.md
- CHANGES.md
- CONTRIBUTING.md
# add more exclude rules, e.g. .ci, .dev, .github
- .ci
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.ci and .github can mean change in the pipeline. We want to run pipelines in those cases

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the mistake, I would fix it.

@kunaltyagi
Copy link
Member

Regarding the svg image, thoughts on using something like PlantUML? Sample code + image here

@ueqri
Copy link
Contributor Author

ueqri commented Jun 15, 2021

Thank you for your kind review!

Could we have a single git diff stage and set the variables there?

In the latest commit, two git diff stages are separated to two pipelines(main & docs pipelines).

But sharing variables across pipelines in Azure isn't well implemented according to the official documents. If we want to do this, we need a variable groups which can't be created in YAML. Reference.

So could we just keep the duplicate until we find a better way to address the issue?

What's the benefit of using pipeline trigger compared to just having them as different stages, included from a separate file? (Since GCC -> generate doc + tutorials is 100% assured)

Although introducing another pipelines may be not a good choice for Azure Ops, pipeline trigger is much smoother to maintain the CI than the flow-control methods for stages or jobs.

The stages are mostly supposed to run sequentially (run only once, only after certain stage completes), depending on the position or specific parameter in YAML. So the control of docs stages (without pipeline trigger) will be quite tough. The detailed discussion is as follows.

The trigger for docs stages are only for two reasons:

  • Only documentations change
  • Build GCC stage completes successfully (implying it has codes changed)

Here are some relevant solutions:

  • If we use dependsOn: build_gcc or dependsOn: OnlyDocsChangeDiff for docs stage, the stage will be skipped if no codes changed or no docs change, respectively.
  • If we use conditions to control docs stage in YAML, we would add 1) OnlyDocsChangeDiff false => build_gcc OK => docs stage; 2) OnlyDocsChangeDiff true => docs stage. And use OR(... , ...) to combine them. Then if we use dependsOn: [ ] to avoid sequential running, what concerns me is the undefined behavior that a parallel stage fetch the status of others. If we put the docs stage after build_gcc without using parallel, the docs will skip together with build_gcc.

Therefore, I think pipeline trigger is a better tool to carry these complex flow-control tasks.

Regarding the svg image, thoughts on using something like PlantUML? Sample code + image here

Thanks for your advice! 😀 I'd like to try the UML form, which is more logic, although the previous Draw.io is easy to create and drag.

@kunaltyagi
Copy link
Member

Thanks, your reasoning is quite solid. The PR looks good to me except the image (text preferred)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants